package com.skzh.unflyzone.service.Impl;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.DateUtils;
import com.skzh.common.utils.SecurityUtils;
import com.skzh.unflyzone.domain.HxUnfly;
import com.skzh.unflyzone.mapper.HxUnflyMapper;
import com.skzh.unflyzone.service.IHxUnflyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zr
 * @Description 环形禁飞区接口实现类
 * @Date 2025/3/26 9:55
 */
@Service
public class HxUnflyServiceImpl implements IHxUnflyService {

    @Autowired
    private HxUnflyMapper hxUnflyMapper;

    /**
     * 新建环形禁飞区
     */
    @Override
    public int insertHxUnfly(HxUnfly hxUnfly) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        hxUnfly.setCreateBy(loginUser.getUsername());
        hxUnfly.setCreateTime(DateUtils.getNowDate());
        //获取当前时间并格式化为字符串
        String currentTimeStr = DateUtils.parseDateToStr("yyyyMMddHHmmss", DateUtils.getNowDate());
        hxUnfly.setHxName("环形禁飞区" + currentTimeStr);
        return hxUnflyMapper.insertHxUnfly(hxUnfly);
    }

    /**
     * 查询环形禁飞区
     */
    @Override
    public List<HxUnfly> selectHxList(HxUnfly hxUnfly) {
        return hxUnflyMapper.selectHxUnflyList(hxUnfly);
    }

    /**
     * 根据ID删除环形禁飞区
     * */
    @Override
    public int deleteHxUnflyById(Long id) {
        return hxUnflyMapper.deleteHxUnflyById(id);
    }

}
